module.exports = {
  emotions: [
    { id: 1, name: '微笑', code: '[微笑]', url: '/haoduogeni/common/static/add-account-blue.png' },
    { id: 2, name: '大笑', code: '[大笑]', url: '/haoduogeni/common/static/add-icon.png' },
    { id: 3, name: '可爱', code: '[可爱]', url: '/haoduogeni/common/static/add-icon.png' },
    { id: 4, name: '酷', code: '[酷]', url: '/haoduogeni/common/static/add-icon.png' },
    { id: 5, name: '哭', code: '[哭]', url: '/haoduogeni/common/static/add-icon.png' },
    { id: 6, name: '害羞', code: '[害羞]', url: '/haoduogeni/common/static/add-icon.png' },
    { id: 7, name: '生气', code: '[生气]', url: '/haoduogeni/common/static/add-icon.png' },
    { id: 8, name: '惊讶', code: '[惊讶]', url: '/haoduogeni/common/static/add-icon.png' },
    // 可以添加更多表情...
  ],
  
  // 将文本中的表情代码转换为图片
  parseEmotions: function(text) {
    console.log('11111111111')
    let result = text;
    this.emotions.forEach(emotion => {
      const regex = new RegExp(emotion.code, 'g');
      result = result.replace(regex, `<img src="${emotion.url}" style="width:20px;height:20px;vertical-align:middle;" />`);
      console.log(result,'result')
    });
    return result;
  },
  
  // 将图片标记转换回表情代码（用于编辑）
  reverseParse: function(html) {
    let result = html;
    this.emotions.forEach(emotion => {
      const imgTag = `<img src="${emotion.url}" style="width:20px;height:20px;vertical-align:middle;" />`;
      result = result.replace(new RegExp(imgTag, 'g'), emotion.code);
    });
    return result;
  }
};